function toSum (n) {
  let he = 0 // 初始化
  while (n) {
    he += n % 10
    n = Math.floor(n / 10)
  }
  return he
}
console.log(toSum(10));